package com.yfkj.receiver.mq.rabbitmq;

import com.yfkj.support.constans.MessageQueuePipeline;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 启动rabbitmq
 */

@Configuration
@ConditionalOnProperty(name = "yfkj.mq.pipeline", havingValue = MessageQueuePipeline.RABBIT_MQ)
public class RabbitMqStart {

    @Value("${yfkj.rabbitmq.exchange.name}")
    private String exchangeName;

    /**
     *配置交换机，实际使用中不用更改
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange( exchangeName,true,false);
    }

    /**
     * 配置队列，不同类型业务会使用到不同队列
     */
    @Bean
    public Queue testQueue(){
        return new Queue(RabbitMqConstant.testQueue,true);
    }

    /**
     *将上面配置的队列绑定到RouteKey上，发送端通过RouteKey就可以将消息发送到本队列中
     */
    @Bean
    public Binding testBindingBuilder(){
        return BindingBuilder.bind(testQueue()).to(directExchange()).with(RabbitMqConstant.testRouteKey);
    }

}
